home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
general
/
viewers
/
polyview
/
polyvw31.lha
/
Polyview3.1
/
new
/
pvmain.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-24
|
15KB
|
492 lines
/*****************************************************************************
* NCSA Polyview 3.1 *
* *
* Version 3.1 changes and additions by Gilles Bourhis. *
* Version 3 changes and additions by Marc Andreessen. *
* Version 2 by Brian Calvert. *
* *
* Software Development Group *
* National Center for Supercomputing Applications *
* University of Illinois at Urbana-Champaign *
* *
* This is BETA release software. As such it may contain software bugs and *
* exhibit inconsistencies. *
* *
* Please send bug reports to polyview@ncsa.uiuc.edu. *
* *
* Copyright (c) 1992 The Board of Trustees of the University of Illinois. *
* *
* Permission to use, copy, and modify this software and its *
* documentation for educational, research, and non-profit purposes is *
* hereby granted, provided that the above copyright notice, the original *
* authors names, and this permission notice appear in all such copies. *
* Any distribution of this software requires the explicit and written *
* authorization of the authors. *
* *
* The University of Illinois makes no representations about the *
* suitability of this software for any purpose. It is provided "as is" *
* without warranty of any kind. *
*****************************************************************************/
/* $Id: pvmain.c,v 1.4 93/08/24 10:30:26 gbourhis Exp $ */
#ifdef RCSLOG
$Log: pvmain.c,v $
* Revision 1.4 93/08/24 10:30:26 gbourhis
* replace version string 3.0 by 3.1.
*
* Revision 1.3 92/09/30 18:36:36 marca
* Fixed FatalProblem message.
*
* Revision 1.2 1992/09/19 03:07:58 marca
* Removed 'Beta' in window title.
*
* Revision 1.1 1992/09/18 10:55:26 marca
* Initial revision
*
#endif
#include "pv.h"
#include <signal.h>
#include <net.h>
/* Global pointer to state. */
state_t *gstate;
/* ------------------------------ initialize ------------------------------ */
static char *script_name = NULL;
static char *transcript_name = NULL;
static char *dtmin_port = NULL;
static char *dtmout_port = NULL;
static int no_sigcatcher = 0;
static int no_core = 0;
/* Skip past a single argument. */
#define ArgInc { argv++; argc--; }
static int initialize(state_t *state, int argc, char **argv)
{
while (--argc)
{
++argv;
if (strncmp ("-i", argv[0], 2) == 0)
{
if (argc == 1)
{
fprintf (stderr, "ERROR: must specify filename with -i flag.\n");
fflush (stderr);
return ST_ERROR;
/* NOTREACHED */
}
script_name = argv[1];
ArgInc;
}
else if (strncmp ("-o", argv[0], 2) == 0)
{
if (argc == 1)
{
fprintf (stderr, "ERROR: must specify filename with -o flag.\n");
fflush (stderr);
return ST_ERROR;
/* NOTREACHED */
}
transcript_name = argv[1];
ArgInc;
}
else if (strcmp ("-DTMIN", argv[0]) == 0 ||
strcmp ("-dtmin", argv[0]) == 0)
{
if (argc == 1)
{
fprintf
(stderr, "ERROR: must specify port ID with -DTMIN flag.\n");
fflush (stderr);
return ST_ERROR;
/* NOTREACHED */
}
dtmin_port = argv[1];
ArgInc;
}
else if (strcmp ("-DTMOUT", argv[0]) == 0 ||
strcmp ("-dtmout", argv[0]) == 0)
{
if (argc == 1)
{
fprintf
(stderr, "ERROR: must specify port ID with -DTMOUT flag.\n");
fflush (stderr);
return ST_ERROR;
/* NOTREACHED */
}
dtmout_port = argv[1];
ArgInc;
}
#ifdef __sgi
else if (strcmp ("-dmalloc", argv[0]) == 0)
{
/* Just switch on debugging malloc. */
fprintf (stderr, "Enabling debugging malloc.\n");
mallopt (M_DEBUG, 1);
}
#endif
else if (strcmp ("-nosigcatcher", argv[0]) == 0)
no_sigcatcher = 1;
else if (strcmp ("-nocore", argv[0]) == 0)
no_core = 1;
else if (strncmp ("-h", argv[0], 2) == 0 ||
strncmp ("-u", argv[0], 2) == 0)
{
/* Help. */
fprintf (stdout,
"***************************************************\n");
fprintf (stdout,
"* NCSA Polyview 3.1 *\n");
fprintf (stdout,
"* National Center for Supercomputing Applications *\n");
fprintf (stdout,
"* University of Illinois at Urbana-Champaign *\n");
fprintf (stdout,
"* Questions? Contact polyview@ncsa.uiuc.edu *\n");
fprintf (stdout,
"* *\n");
fprintf (stdout,
"* Command line options: *\n");
fprintf (stdout,
"* -i <filename> : Specify input script name. *\n");
fprintf (stdout,
"* -o <filename> : Specify output script name. *\n");
fprintf (stdout,
"* -DTMOUT <port> : Establish DTM output port. *\n");
fprintf (stdout,
"* -DTMIN <port> : Establish DTM input port. *\n");
fprintf (stdout,
"***************************************************\n");
fflush (stdout);
return ST_ERROR;
/* NOTREACHED */
}
}
/* Initialize data subsystem. */
assert (init_data (state) == ST_OKAY);
return ST_OKAY;
}
static int do_scripts (state_t *state)
{
static FILE *init_fp;
static char *home_dir;
/* If the transcript filename was specified, attempt to open it. */
if (transcript_name != NULL)
if ((state->transcript_fp = fopen(transcript_name, "w")) == NULL )
{
fprintf(stderr, "ERROR: Couldn't open output file '%s'.\n",
transcript_name);
fflush (stderr);
return ST_ERROR;
}
/* If the ".polyview" initialization file is present, open it and */
/* read it. */
init_fp = fopen (".polyview", "r");
if (init_fp != (FILE *)NULL)
{
stprintf (state, "Reading './.polyview' script.");
load_script(state, init_fp);
fclose(init_fp);
}
else
{
/* NEW: Look for ~/.polyview */
home_dir =
strcpy ((char *)PVMALLOC (sizeof(char) * 256), getenv("HOME"));
init_fp = fopen (strcat (home_dir, "/.polyview"), "r");
if (init_fp != (FILE *)NULL)
{
stprintf (state, "Reading '$HOME/.polyview' script.\n");
load_script(state, init_fp);
fclose(init_fp);
}
PVFREE (home_dir);
}
/* If the script filename was specified, attempt to open it. */
if (script_name != NULL)
if ((state->script_fp = fopen(script_name, "r")) == NULL)
{
stprintf (state, "ERROR: Couldn't open input file '%s'.\n",
script_name);
return ST_ERROR;
}
else
{
stprintf (state, "Reading '%s' script.\n", script_name);
load_script(state, state->script_fp);
fclose(state->script_fp);
}
return ST_OKAY;
}
/* --------------------------------- main --------------------------------- */
/* ----------------------------- X Resources ------------------------------ */
/* We assume that we parse options first, use what we want, then pass
to Xt routines. Thus, -i is explicitly disabled for Xt here. */
static XrmOptionDescRec options[] = {
{"-fn", "*fontList", XrmoptionSepArg, NULL},
{"-ft", "*XmText*fontList", XrmoptionSepArg, NULL},
{"-fm", "*menubar*fontList", XrmoptionSepArg, NULL},
/* Turn off the iconify flag. */
{"-i", "*foobar", XrmoptionSepArg, NULL},
};
static String fallback_resources[] = {
"*background: light grey",
"*foreground: black",
#ifdef _IBMR2
"*XmCommand*troughColor: #7d9ec0",
"*scrolledtextSW*troughColor: #7d9ec0",
"*XmScale*troughColor: #7d9ec0",
"*fsb*troughColor: #7d9ec0",
"*menubar*background: #7d9ec0",
#endif
#ifdef __sgi
"*XmCommand*troughColor: SGILightBlue",
"*scrolledtextSW*troughColor: SGILightBlue",
"*XmScale*troughColor: SGILightBlue",
"*fsb*troughColor: SGILightBlue",
"*menubar*background: SGILightBlue",
#endif
"*menubar*foreground: black",
"*question*background: light grey",
"*question*foreground: black",
"*helpdialog*background: light grey",
"*helpdialog*foreground: black",
"*fsb*XmText*width: 420",
"*highlightThickness: 2",
"*XmLabelGadget*highlightThickness: 0",
"*keyboardFocusPolicy: pointer",
"*highlightOnEnter: True",
"*fontList: -*-helvetica-medium-r-normal-*-14*iso8859-1",
"*XmText*fontList: -*-lucidatypewriter-medium-r-normal-*-14*iso8859-1",
"*menubar*fontList: -*-helvetica-bold-o-normal-*-14*iso8859-1",
/* This doesn't work. Dunno why not. */
"*infozoid*XmLabel*fontList: *times*62*",
"*fillOnSelect: True",
"*selectColor: #ffff00",
"*cascadebutton*marginWidth: 8",
"*title: NCSA Polyview 3.1",
NULL,
};
static XmxCallback (GUItimeoutThree)
{
char line[MAXLINELEN];
/* Start processing actions. */
gstate->no_actions = FALSE;
/* Open DTM input port if flag is specified. */
if (dtmin_port != NULL)
{
sprintf (line, "dtm in %s\0", dtmin_port);
parse_line (gstate, line, FALSE);
}
/* Open DTM output port if flag is specified. */
if (dtmout_port != NULL)
{
sprintf (line, "dtm out %s\0", dtmout_port);
parse_line (gstate, line, FALSE);
}
/* Load startup scripts. */
do_scripts (gstate);
#ifdef DMF
parse_line (gstate, "window open polyview DMF", TRUE);
parse_line (gstate, "palette use rgb", TRUE);
parse_line (gstate, "draw outlined", TRUE);
#endif
return;
}
/* ------------------------------------------------------------------------ */
/* ---------------------------- SIGNAL HANDLER ---------------------------- */
/* ------------------------------------------------------------------------ */
static void RealFatal (void)
{
signal(SIGBUS,0);
signal(SIGSEGV,0);
signal(SIGILL,0);
if (!no_core)
abort();
else
exit(0);
}
static void FatalProblem(int sig, int code, struct sigcontext *scp,
char *addr)
{
fprintf(stderr,"\n\nCongratulations, you have found a bug in\n");
fprintf(stderr,"NCSA Polyview 3.1.\n\n");
fprintf(stderr,"If a core file was generated in your directory,\n");
fprintf(stderr,"please run 'dbx polyview' and then type:\n");
fprintf(stderr," dbx> where\n");
fprintf(stderr,"and send the results to polyview@ncsa.uiuc.edu.\n\n");
fprintf(stderr,"...exiting Polyview now.\n\n");
if (gstate->transcript_fp)
fflush (gstate->transcript_fp);
if (COMdtm_out_active_p (gstate))
{
/* Disconnect gracefully. */
if (NetSendDisconnect (NULL, RealFatal, RealFatal))
goto done;
while (1)
NetTryResend ();
}
done:
RealFatal ();
/* NOTREACHED */
}
/* ------------------------------------------------------------------------ */
/* --------------------------------- MAIN --------------------------------- */
/* ------------------------------------------------------------------------ */
main (int argc, char **argv)
{
/* State struct itself. */
state_t state;
/* Global pointer to state struct. */
gstate = &state;
/* Don't start executing actions until we say so. */
gstate->no_actions = TRUE;
/* Parse command-line args and initialize data
before opening any windows. */
if (initialize (&state, argc, argv) != ST_OKAY)
exit_polyview ();
/* Redirect signals to our own signal catcher. */
if (!no_sigcatcher)
{
signal(SIGBUS, FatalProblem);
signal(SIGSEGV, FatalProblem);
signal(SIGILL, FatalProblem);
}
/* Set up Motif and go into XtAppMainLoop. */
/* Initialize Xmx library. */
XmxStartup ();
/* Connect to Xt. */
gstate->base = XtAppInitialize
(&(gstate->app_context), "Polyview", options, XtNumber(options),
&argc, argv, fallback_resources, Xmx_wargs, Xmx_n);
#ifdef TRANSLATIONS
XtAppAddActions
(gstate->app_context, pviewActionsTable, XtNumber (pviewActionsTable));
pviewTransTable = XtParseTranslationTable (pviewTranslations);
#endif
/* Having filled in base and app_context fields, send gstate
to post_status to get the status window up. */
post_status (gstate);
/* Realize the status window. */
XtRealizeWidget (gstate->base);
/* Add timeouts for controlling global action. */
/* Everything's in timeout two for the moment. */
#if 0
XtAppAddTimeOut (gstate->app_context, 50, GUItimeoutOne, True);
#endif
XtAppAddTimeOut (gstate->app_context, 50, GUItimeoutTwo, True);
#ifdef DO_AUDIO
/* Sound. */
gstate->can_use_sound = InitSound ();
#endif
/* Initial timeout for reading scripts and implementing results
from command-line args. */
XtAppAddTimeOut (gstate->app_context, 100, GUItimeoutThree, True);
/* Process events. */
XtAppMainLoop (gstate->app_context);
/* NOTREACHED */
}
/* ---------------------------- exit_polyview ----------------------------- */
static void RealExit (void)
{
exit (0);
}
void exit_polyview (void)
{
if (gstate->transcript_fp)
fflush (gstate->transcript_fp);
if (COMdtm_out_active_p (gstate))
{
/* Disconnect gracefully. */
if (NetSendDisconnect (NULL, RealExit, RealExit))
RealExit ();
while (1)
NetTryResend ();
}
RealExit ();
}
/* -------------------------- coredump_polyview --------------------------- */
void coredump_polyview (void)
{
if (gstate->transcript_fp)
fflush (gstate->transcript_fp);
abort ();
/* NOTREACHED */
}